package com.weishe.weichar;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class Weather implements WritableComparable<Weather> {

	private int year;
	private int month;
	private double temperature;
	
	public Weather(){
		
	}

	public Weather(int year, int month, double temperature) {
		this.year = year;
		this.month = month;
		this.temperature = temperature;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public double getTemperature() {
		return temperature;
	}

	public void setTemperature(double temperature) {
		this.temperature = temperature;
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		this.year = in.readInt();
		this.month = in.readInt();
		this.temperature = in.readDouble();

	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(year);
		out.writeInt(month);
		out.writeDouble(temperature);
	}

	@Override
	public int compareTo(Weather w) {
		int result = Integer.compare(year, w.getYear());

		if (result == 0) {
			result = Integer.compare(month, w.getMonth());
			if (result == 0) {
				result = Double.compare(temperature, w.getTemperature());
			}
		}
		return result;
	}

}
